package com.xxbb.chapter_1.dome4_GuessTheNumber;

import java.util.Random;
import java.util.Scanner;

public class RandomNumber {
    public int getNumber(int limit) {
        Random random = new Random();
        return random.nextInt(limit);
    }

    public void start() {
        //获取随机数
        int n = this.getNumber(100);
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请输入数字：");
            int i = sc.nextInt();
            if (i < n)
                System.out.println("猜小了！");

            else if (i > n)
                System.out.println("猜大了！");
            else {
                System.out.println("恭喜你！猜对了。");
                return;
            }
        }
    }
}
